<?php 

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Auth\Guard;
use Auth;

class EntrustRole
{
	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request $request
	 * @param  Closure $next
	 * @param  $roles
	 * @return mixed
	 */
	public function handle($request, Closure $next, $roles)
	{
		if (Auth::guard('admin')->guest() || !Auth::guard('admin')->user()->hasRole(explode('|', $roles))) {
			abort(403);
		}
		return $next($request);
	}
}
